home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
MultiplePa
< prev
next >
Wrap
Text File
|
1995-06-28
|
2KB
|
34 lines
Multiple Parsers
Previous: <Declarations=>Declaratio> * Next: <Interface=>Interface> * Up: <Grammar File=>GrammarFil>
#Wrap on
{fH3}Multiple Parsers in the Same Program{f}
Most programs that use Bison parse only one language and therefore contain
only one Bison parser. But what if you want to parse more than one
language with the same program? Then you need to avoid a name conflict
between different definitions of {fCode}yyparse{f}, {fCode}yylval{f}, and so on.
The easy way to do this is to use the option {fEmphasis}-p {fStrong}prefix{f}{f}
(\*Note <Invocation=>Invocation>: Invoking Bison). This renames the interface functions and
variables of the Bison parser to start with {fStrong}prefix{f} instead of
{fEmphasis}yy{f}. You can use this to give each parser distinct names that do
not conflict.
The precise list of symbols renamed is {fCode}yyparse{f}, {fCode}yylex{f},
{fCode}yyerror{f}, {fCode}yynerrs{f}, {fCode}yylval{f}, {fCode}yychar{f} and
{fCode}yydebug{f}. For example, if you use {fEmphasis}-p c{f}, the names become
{fCode}cparse{f}, {fCode}clex{f}, and so on.
{fStrong}All the other variables and macros associated with Bison are not
renamed.{f} These others are not global; there is no conflict if the same
name is used in different parsers. For example, {fCode}YYSTYPE{f} is not
renamed, but defining this in different ways in different parsers causes
no trouble (\*Note <Value Type=>ValueType>: Data Types of Semantic Values).
The {fEmphasis}-p{f} option works by adding macro definitions to the beginning
of the parser source file, defining {fCode}yyparse{f} as
{fCode}{fStrong}prefix{f}parse{f}, and so on. This effectively substitutes one
name for the other in the entire parser file.